package com.example.demo.Controller;

import com.example.demo.Dao.StuScoreDao;
import com.example.demo.Dao.StudentDao;
import com.example.demo.Model.Course;
import com.example.demo.Model.StuScore;
import com.example.demo.Model.Student;
import com.example.demo.Model.applylev;
import com.example.demo.Service.StudentService.ApplylevService;
import com.example.demo.Service.StudentService.ScoreService;
import com.example.demo.Service.TeacherService.CourseService;
import com.example.demo.Service.TeacherService.StuScoreService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class HtmlController {
    @Resource
    private ScoreService scoreservice;
    @Resource
    private CourseService courseservice;
    @Resource
    private StuScoreService stuscoreservice;
    @Resource
    private StuScoreDao stusocoredao;
    @Resource
    private ApplylevService applylevservice;

    @RequestMapping("/addcourse")//老师添加课程
    public String addCourse(){
        return "Teacher/addcourse";
    }
    @RequestMapping("/selectCourse")//学生选课
    public String selectCourse(){
        return "student/selectCourse";
    }
    @RequestMapping("/addScore")//老师添加成绩
    public String addScore(){
        return "teacher/addScore";
    }

    @RequestMapping("/searchByColName")//学生查找成绩
    public String searchByColName(){
        return "student/searchByColName";
    }



    //学生查询成绩
    @RequestMapping("/search_By_scyear")
    public String search_stuscore(String scyear, Model model, HttpSession session){
//        if (scyear.equals(null)){
//            scyear="1";
//        }
        String stuid=session.getAttribute("stuID").toString();
        System.out.println("学生查询成绩");
        System.out.println(stuid);
        List<StuScore> stuscore=stusocoredao.findBy_stuID_scyear(stuid,scyear);
//        List<StuScore> stuscore=stuscoreservice.findByStuID(stuid);
        model.addAttribute("stuScore",stuscore);
        return "student/searchByColName";
    }


    @RequestMapping("/add_course")
    public String add_course(Course course, HttpSession session){
        String teID=session.getAttribute("teID").toString();
        course.setTeID(teID);
        courseservice.save(course);
        return "teacher/addcourse";
    }

    @RequestMapping("/add_apply")//学生
    public String add_apply(applylev apply,HttpSession session){
        String stuid=session.getAttribute("stuID").toString();
        apply.setSituation("未批阅");
        apply.setStuID(stuid);
        applylevservice.save(apply);
        return "student/applyforLeave";
    }

    @RequestMapping("/applyforLeave")//学生请假申请
    public String applyforLeave(){
        return "student/applyforLeave";
    }
    @RequestMapping("/Approval")//老师审批请假
    public String Approval(){
        return "teacher/Approval";
    }
    @RequestMapping("/showApply")//学生查看请假
    public String showApply(){
        return "student/showApply";
    }



    @Resource
    private StudentDao studentdao;
    @RequestMapping("/StuPersonPage")//学生个人信息
    public String Student(Model model,HttpSession session){
        String stuID=session.getAttribute("stuID").toString();
        System.out.println("查看个人信息");
        System.out.println(stuID);
        Student stu=studentdao.findByStuID(stuID);
        System.out.println(stu);
        model.addAttribute("Student",stu);
        return "student/StuPersonPage";
    }
    @RequestMapping("/saveEmail")//学生个人信息
    public String saveEmail(String useremail,Model model,HttpSession session){
        String stuID=session.getAttribute("stuID").toString();
        System.out.println("修改学生邮箱");
        System.out.println(stuID);
        System.out.println(useremail);
        studentdao.update_email(useremail,stuID);

        return Student(model,session);
    }

    @RequestMapping("/update_mail")//学生个人信息
    public String update_email(){
        return "student/update_mail";
    }
}
